var TRE_FEE_DETAIL_PATH = "";
var TRE_FEE_TYPE_PATH = "";

function setPathPrefix(treFeeDetailPath,treFeeTypePath) {
	TRE_FEE_DETAIL_PATH = treFeeDetailPath;
	TRE_FEE_TYPE_PATH = treFeeTypePath;
}
var TRE_FEE_DETAIL = function(){
	this.init();
};
/**
 * 初始化方法
 */
TRE_FEE_DETAIL.prototype.init = function(){
	var self = this;
	self.expand();
	WASP_WIDGET.triggerSubProductInfoSelect("subPrdCode", null, {"url": "queryMatchSubPrdLineList.do"});
	self.selectFeeCode();
	// 给select2组件加载样式
	WASP_WIDGET.initializeSelectStyle();
}
/**
 * 拓展方法
 */
TRE_FEE_DETAIL.prototype.expand = function(){
	var self = this;
	
	self.addTreFeeDetail = function() {
		SubmitAndPreventSecond("treFeeDetailDeleteForm",function() {
//			if(!$("form[name='treFeeDetailDeleteForm']").valid()) {
//				toastr.warning('', '请完善信息');
//				return false;
//			}
			// 浮动费率必填校验
			return true;
		}, true);
	};
	//加载费用类型列表
	self.selectFeeCode =  function(){
		var actionUrl = TRE_FEE_TYPE_PATH + "treFeeTypeList.do";
		$.ajax({
			type : "POST",
			url : actionUrl,
			dataType : "json",
			success : function(data){
				if(data){
					data = JSON.parse(data);
					$.each(data, function (index, item) {
						$("#feeCode").append("<option value='"+item.feeCode+"'>"+item.feeName+"</option>");
				    });
				}else{
					
				}
			},
			error : function(e) {
				toastr.error(e,"系统出现异常！");
			},
		});
	};
	
	//选择费用类型
	self.customAddFee =  function(){
		$('*[name="show_custom_fee"]').show();
		
		var feeName = $("#feeCode").find("option:selected").text();
		$('*[name="show_custom_fee_title"]').html(feeName);
		
		$('*[name="feeName"]').val(feeName);
		$('*[name="feeName1"]').val(feeName);
		
	};
	
	//费用或收益
	self.chooseFeeType =  function(elem){
		$("#customType").show();
		$('*[name="fee_type"]').each(function(index,element){
	    	$(element).removeClass('checked');
	    });
		$(elem).addClass('checked');
		var data = '';
		$('*[name="fee_type"].checked').each(function(index,element){
			data += $(element).attr("value");
		});
		
		
		
		$('#treFeeDetailDeleteForm').attr('action', TRE_FEE_DETAIL_PATH + "deleteTreFeeDetailInfo.do");
		if(data.length > 0){
			if(data == 'fee'){
				$("#yieldContainer :input").attr("disabled", "disabled");
				$("#feeContainer :input").removeAttr("disabled");
				
				$('*[name="customTypeTitle"]').html("费用类型");
				$('*[name="custom_fee"]').show();
				$('*[name="custom_yield"]').hide();
				$('*[name="show_custom_yield"]').hide();
				$("#feeType").val("fee");
			}else if(data == 'yield'){
				$("#feeContainer :input").attr("disabled", "disabled");
				$("#yieldContainer :input").removeAttr("disabled");
				
				$('*[name="custom_fee"]').hide();
				$('*[name="customTypeTitle"]').html("收益类型");
				$('*[name="show_custom_fee"]').hide();
				$('*[name="show_custom_yield"]').show();
				$('*[name="custom_yield"]').show();
				$("#feeType").val("yield");
			}
		}
	};
	
}
